package br.bd;	

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

public class BdControl {
	private Connection con;
	private Properties properties;
	
	public Connection getConnection() throws SQLException {
		if(con == null) {
			Properties properties = getProperties();
			con = DriverManager.getConnection(properties.getProperty("url_db"), properties.getProperty("user_db"), properties.getProperty("pass_db"));
		}
		return con;
	}
	
	public ResultSet executeInsert(PreparedStatement preparedStatement) {
		return null;
	}
	
	public void close() {
		
	}
	
	public Properties getProperties() {
		if(properties == null) {
			File file = new File("conf\\spa.properties");
			try {
				properties = new Properties();
				properties.load( new FileInputStream( file ) );  
	        } catch (FileNotFoundException ex) {  
	            ex.printStackTrace();  
	        } catch (IOException ex) {  
	            ex.printStackTrace();  
	        }  
		}
		return properties;
	}
	public void setProperties(Properties properties) {
		this.properties = properties;
	}


}
